package com.nepu.gmall.realtime.app.func;

import com.nepu.gmall.realtime.util.KafkaUtils;
import com.nepu.gmall.realtime.util.KeywordUtil;
import org.apache.flink.table.annotation.DataTypeHint;
import org.apache.flink.table.annotation.FunctionHint;
import org.apache.flink.table.functions.TableFunction;
import org.apache.flink.types.Row;

import java.io.IOException;
import java.util.List;

/**
 * @author chenshuaijun
 * @create 2023-02-27 22:09
 */
@FunctionHint(output = @DataTypeHint("ROW<word STRING>"))
public class KeywordUDTF extends TableFunction<Row> {

    public void eval(String keywords) {
        try {
            List<String> words = KeywordUtil.splitKeyword(keywords);
            for (String word : words) {
                collect(Row.of(word));
            }
        } catch (IOException e) {
            collect(Row.of(keywords));
        }
    }
}
